#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main() // 排序+滑动窗口
{
    int n = 0, k = 0;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    int left = 0, right = 0;
    int res = 1;
    while(right < n)
    {
        while(arr[right] - arr[left] > k)
        {
            ++left;
        }
        res = max(res, right - left + 1);
        ++right;
    }
    cout << res << endl;
    return 0;
}